<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import=" com.six.entity.Users" %>
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="UTF-8">
<title>购物车</title>
<link rel="stylesheet" href="layui/css/layui.css" />
<script type="text/javascript" src="layui/layui.js"></script>
</head>
<body>
	<jsp:include page="/header"></jsp:include>
		 <!--=====================
    Breadcrumb Aera Start
    =========================-->
    <div class="breadcrumbs_area">
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <div class="breadcrumb_content">
                        <ul>
                            <li>
                                <h1><a href="index">首页</a></h1>
                            </li>
                            <li>购物车</li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--=====================
    Breadcrumb Aera End
    =========================-->
	 <%
                        HttpSession s=request.getSession();
                        if(s.getAttribute("users_session")==null){
                        	response.sendRedirect(request.getContextPath()+"/login_car.jsp");
                        }else{
                        	Users u=(Users)s.getAttribute("users_session");
                        %>
    <!--======================
    Shopping Cart area Start
    ==========================-->
    <div class="cart-area">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <form action="#" class="layui-form" onsubmit="false">
                        <!-- Cart Title Start -->
                        <div class="cart-title">
                            <h5 class="last-title mt-50 mb-20">购物车</h5>
                        </div>
                        <!-- Cart Title End -->
                        <!-- Cart Table Area Start -->
                        <div class="table-desc">
                            <div class="cart-page table-responsive">
                                <table>
                                    <thead>
                                        <tr>
                                            <th class="product-image">图片</th>
                                            <th class="product-name">产品名称</th>
                                            <th class="product-price">价钱</th>
                                            <th class="product-quantity">数量</th>
                                            <th class="product-total">总价钱</th>
                                            <th class="product-remove">删除</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    		<c:forEach items="${shoppcar }" var="s">
	                                    		 <tr>
			                                            <td class="product-image"><input id="check" type="checkbox" value="${s.Pid }"  name="${s.Pid }"><!-- 根据 商品id去查询添加-->
			                                            <a href="${s.PskipUrl }"><img style="width: 100px;height: 100px;" src="${s.Purl }" alt=""></a></td>
			                                            <td class="product-name"><a href="${s.PskipUrl }">${s.Pname }</a></td>
			                                            <td hidden="hidden"><input  autocomplete="off" class="layui-input" type="text" lay-verify="required" name="Shid" id="Shid"  value="${s.Shid }"></td>
			                                            <td class="product-price"><input hidden="hidden" value="${s.Pprice }" id="Pprice"/>${s.Pprice }</td>
			                                            <td class="product-quantity"><label>数量</label> <input name="Shshopp_sum" onchange="sss(this)"   class="Shshopp_sum" min="1" max="${s.Srepertory }" value="${s.Shshopp_sum }" type="number"  lay-submit lay-filter="form"></td>
			                                            <td class="product-total" id="zongerid">${s.Standby_application_one }</td>
			                                            <td class="product-remove"><a href="shoppcar_del?Shid=${s.Shid }"><i class="fa fa-trash-o"></i></a></td>
			                                            <td hidden="hidden"><input  autocomplete="off" class="layui-input" type="text" lay-verify="required" name="Standby_application_one" id="Standby_application_one"  value="${s.Standby_application_one }"></td>
		                                        </tr>
                                    		</c:forEach>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <!-- Cart Table Area End -->
                        <!-- Coupon Area Start -->
                        <div class="coupon-area">
                            <div class="row">
                                <div class="col-lg-6 col-md-6">
                                </div>
                                <div class="col-lg-6 col-md-6">
                                    <div class="coupon-code right">
                                        <h3>购物车总计</h3>
                                        <div class="coupon-inner">
                                            <div class="cart-subtotal">
                                                <p>总</p>
                                                <p class="cart-amount" id="zongji">${zonger[0].zonger }</p>
                                            </div>
                                            <div class="checkout-btn">
                                                <a href="shoppcar_detele">清空购物车</a>
                                                <a href="checkout">进行结算</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- Coupon Area End -->
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!--======================
    Shopping Cart area End
    ==========================-->
	<%} %> 
<!--===================
     footer area start 
    ===================-->
	<footer class="mt-30">
		<!-- Newslatter area start -->
		<div class="newsletter-group">
			<div class="container">
				<div class="row align-items-center">
					<div class="col-lg-6 col-12">
						<div class="newsletter-inner d-flex align-items-center">
							<i class="fa fa-envelope-open-o"></i>
							<div class="newsletter-title">
								<h1 class="sign-title">注册我们的通讯</h1>
								<p>获取有关我们最新商店和特惠信息的电子邮件更新。</p>
							</div>
						</div>
					</div>
					<div class="col-lg-6 col-12">
						<div class="newsletter-box">
							<form id="mc-form" class="mc-form">
								<input type="email" id="mc-email" class="email-box"
									placeholder="输入你的电子邮箱" name="EMAIL">
								<button id="mc-submit" class="newsletter-btn" type="submit">订阅</button>
							</form>
							<!-- mailchimp-alerts Start -->
							<div class="mailchimp-alerts text-centre">
								<div class="mailchimp-submitting"></div>
								<!-- mailchimp-submitting end -->
								<div class="mailchimp-success text-success"></div>
								<!-- mailchimp-success end -->
								<div class="mailchimp-error text-danger"></div>
								<!-- mailchimp-error end -->
							</div>
							<!-- mailchimp-alerts end -->
						</div>
					</div>
				</div>
			</div>
		</div>
		<!-- Newslatter area End -->
		<!-- Footer Top Start -->
		<div class="footer-top mt-50 mb-40">
			<div class="container">
				<div class="row">
					<div class="col-lg-4">
						<div class="footer-single-widget">
							<div class="footer-logo mb-40">
								<a href="index"><img
									src="assets/images/logo/pos-circle-logo.jpg" alt=""></a>
							</div>
							<div class="widget-body">
								<div class="widget-address mt-30 mb-20">
									<p>
										<strong>地址:</strong>新乡市，红旗区，新乡职业技术学院
									</p>
									<p>
										<strong>联系电话:</strong> (800) 123 456 - (800) 123 456.
									</p>
									<p>
										<strong>电子邮箱:</strong> support@circleshop.com
									</p>
								</div>
							</div>
						</div>
					</div>
					<div class="col-lg-8">
						<div class="row">
							<div class="col-lg-3 col-md-3 col-6">
								<div class="widgets_container">
									<h6>信息</h6>
									<div class="footer_menu">
										<ul>
											<li><a href="#">隐私政策</a></li>
											<li><a href="#">条款及细则</a></li>
										</ul>
									</div>
								</div>
							</div>
							<div class="col-lg-3 col-md-3 col-6">
								<div class="widgets_container">
									<h6>我的账户</h6>
									<div class="footer_menu">
										<ul>
											<li><a href="#">我的帐户</a></li>
											<li><a href="#">心愿单</a></li>
										</ul>
									</div>
								</div>
							</div>
							<div class="col-lg-3 col-md-3 col-6">
								<div class="widgets_container">
									<h6>快速找到</h6>
									<div class="footer_menu">
										<ul>
											<li><a href="#">历史悠久</a></li>
											<li><a href="#">新闻快报</a></li>
										</ul>
									</div>
								</div>
							</div>
							<div class="col-lg-3 col-md-3 col-6">
								<div class="widgets_container">
									<h6>客户服务</h6>
									<div class="footer_menu">
										<ul>
											<li><a href="#">网站地图</a></li>
											<li><a href="#">联系我们</a></li>
										</ul>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<!-- Footer Top End -->
	</footer>
	<!--===================
     footer area end 
    ===================-->


	<!-- Use the minified version files listed below for better performance and remove the files listed above -->
	<script src="assets/js/vendor/vendor.min.js"></script>
	<script src="assets/js/plugins/plugins.min.js"></script>
	<script src="assets/js/jquery-1.8.2.js"></script>
	<script type="text/javascript">
	 
	function sss(obj){
	        var oldValue = $(obj).val();
	        var p1=$(obj).parent();//
	        //1、拿到她的上一个元素  --- input 的值（单价）
	      	 var p2=p1.prev();//拿到上一元素
	      	 var danjia= p2.find('input').val();//上一个元素input里的值
	        //2、拿到她的下一个元素  ---赋值- 当前的数量*单价
	     	 var ressss=  parseFloat(danjia)* parseFloat(oldValue);//赋值
	     	var p4=p1.next();//拿到下一个 元素的
	      	 var p3=p4.html(ressss);//下一个元素td赋值
	     	 //拿到p2的上一个元素
	     	 var p5=p2.prev();
	      	 var id=p5.find('input').val();//拿到p2上一个元素里的input值
	      	 //3，ajax请求  
	      	 //监听提交
				var url = '/shoppingsix/shopping-cart_update';
				$.post(url, {
					'Shshopp_sum':oldValue,
					'Shid':id,
					'Standby_application_one':ressss /* 单个商品的总价 */
				}, function(data) {
					if(data.count>0){
						console.log('修改成功');
						setTimeout(function () {
			            	window.parent.location.reload();
			            }, 1000);
					}
				}, "json"); 
	}
	</script>
	<!-- Main JS -->
	<script src="assets/js/main.js"></script>
	<script type="text/javascript">
	//Demo
	layui.use('form', function() {
		var form = layui.form;
		var $ = layui.jquery;
		/*设置复选框获取焦点之后的样式  */
		$(function() {
				$("#check").focus(function() {
					$("#zongji").html($("#Standby_application_one").val());
					console.log($("#Standby_application_one").val());
				});
				});
				/* 获取焦点样式结束 */
		form.on('submit(*)', function(data){
		    //将页面全部复选框选中的值拼接到一个数组中
		    var arr_box = [];
		    $('input[type=checkbox]:checked').each(function() {
		      arr_box.push($(this).val());
		    });
		    //数组
		    console.log(arr_box);//根据商品id去购物车表查询下单商品的数量，总价格
		    // ["董先生的csdn"]
		    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
		  });
		
	});
	</script>
</body>
</html>